﻿

function getdata(indexpage, indexwhere) {
    poststr = "{\"type\":\"clientlist\",\"pagecurrent\":\"" + indexpage + "\",\"indexwhere\":\"" + indexwhere + "\"}";
    mj_js_ajax("json", poststr, showlist);

}

function search() {
    var quyu = $.trim($("#dateboxs").text());
    var louhao = $.trim($("#building").val());
    var sushe_hoa = $.trim($("#dorm").val());
    var arrey = quyu + "|" + louhao + "|" + sushe_hoa;
    getdata("1", arrey);
}


function showlist(data) {
    if (data.result == "ok") {
        try {
            var record_count = data.record_count;
            var page_curent = data.page_curent;
            var datatable = data.table;

            var str = "";
            var table = document.getElementById("tbodyList");
            $("#tbodyList").empty();
            for (var i = 0; i < datatable.length; i++) {
                var tr = document.createElement("tr");

                var td1 = document.createElement("td");
                td1.innerHTML = datatable[i].area;

                var td2 = document.createElement("td");
                td2.innerHTML = datatable[i].building;

                var td3 = document.createElement("td");
                td3.innerHTML = datatable[i].drom;

                var td4 = document.createElement("td");
                td4.innerHTML = datatable[i].number;


                var td5 = document.createElement("td");
                if (datatable[i].time != null) {
                    td5.innerHTML = datatable[i].time.replace(/-/g, "/").substring(0, 10);
                }
                else { td5.innerHTML = datatable[i].time; }


                var td6 = document.createElement("td");
                var label1 = document.createElement("input");
                label1.id = datatable[i].id;
                label1.setAttribute("type", "button");
                label1.className = "btn btn-default input2 wiht";
                label1.value = "解绑";
                label1.onclick = function () {
                    xiugai(this.id);
                }
                td6.appendChild(label1);
                tr.appendChild(td1);
                tr.appendChild(td2);
                tr.appendChild(td3);
                tr.appendChild(td4);
                tr.appendChild(td5);
                tr.appendChild(td6);
                table.appendChild(tr);
            }

            //下面进行的是分页
            $("#record_shu").text(" 总记录数" + record_count);
            if (record_count % 10 != 0) {
                page_shu = record_count / 10 + 1;
                page_shu = parseInt(page_shu)
            }


            else {
                page_shu = record_count / 10;
            }


            var options = {
                currentPage: page_curent,
                totalPages: page_shu,
                numberOfPages: 5,
                itemTexts: function (type, page, current) {
                    switch (type) {
                        case "first":
                            return "第一页";
                        case "prev":
                            return "上一页";
                        case "next":
                            return "下一页";
                        case "last":
                            return "最后一页";
                        case "page":
                            return page;
                    }
                },
                onPageClicked: function (event, originalEvent, type, page) {
                    getdata(page, "");
                }
            }
            $('#example').bootstrapPaginator(options);
        }

        catch (e) {

        }
    }
    else {
        alert(data.msg);

    }

}
function xiugai(id) {
    poststr = "{\"type\":\"outbinds\",\"code\":\"" + id + "\"}";
    mj_js_ajax("json", poststr, tellresult);
}
function tellresult(data) {
    if (data.result) {
        alert(data.msg);

    }
    else { alert(data.msg) }
}

